//导入接口
import { getRolePages } from "@/api/roles"
import type { QueryRoles,Condition } from "@/api/roles"
import { ElMessage } from "element-plus"
import { reactive, ref } from "vue"

//查询角色的条件
export const queryCondition = reactive({
    name:'',
    size: 5
    
})

//查询角色的结果
export const queryResult = ref<QueryRoles>({
  current: 1,
  records: [],
  pages: 0,
  size: 0,
  total: 0,
})

//查询角色的方法
export const queryRoles = async (params: Condition = {}) => {
    Object.assign(queryCondition, params)
    const {data} = await getRolePages(queryCondition)
    // console.log(res)
    if(data.code === "000000"){
      queryResult.value = data.data
    }else{
      ElMessage.error('获取角色失败')
      throw new Error('获取角色失败')
    }
}
